package net.lab1024.sa.admin.util;


import cn.hutool.core.util.ObjectUtil;
import net.lab1024.sa.admin.common.constant.TaskConstants;
import net.lab1024.sa.base.common.domain.RequestUser;
import net.lab1024.sa.base.common.util.SmartRequestUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 工作流任务工具类
 *
 * @author konbai
 * @createTime 2022/4/24 12:42
 */
public class TaskUtils {

    public static String getUserId() {
        RequestUser requestUser = SmartRequestUtil.getRequestUser();
        return String.valueOf(requestUser.getUserId());
    }

    /**
     * 获取用户组信息
     *
     * @return candidateGroup
     */
    public static List<String> getCandidateGroup() {
        List<String> list = new ArrayList<>();
//        LoginUser user = LoginHelper.getLoginUser();
        RequestUser user = SmartRequestUtil.getRequestUser();
        if (ObjectUtil.isNotNull(user)) {
            // 角色组
            if (ObjectUtil.isNotEmpty(user.getRoleIdList())) {
                user.getRoleIdList().forEach(roleId -> list.add(TaskConstants.ROLE_GROUP_PREFIX + roleId));
            }
            // 部门
            if (ObjectUtil.isNotNull(user.getDepartmentId())) {
                list.add(TaskConstants.DEPT_GROUP_PREFIX + user.getDepartmentId());
                // 部门领导
                if (user.getDeptLeader()) {
                    list.add(String.format(TaskConstants.DEPT_LEADER_GROUP_PREFIX, user.getDepartmentId()));
                }
            }
            // 部门角色
            if (ObjectUtil.isNotEmpty(user.getRoleIdList()) && ObjectUtil.isNotEmpty(user.getDepartmentId())) {
                user.getRoleIdList().forEach(roleId -> list.add(String.format(TaskConstants.DEPT_ROLE_GROUP_PREFIX, user.getDepartmentId(), roleId)));
            }


        }
        return list;
    }
}
